﻿using AutoMapper;
using J.Model;
using J.ProductSet.Application.Command.ClassifiedManagementCommand;
using MediatR;
using SqlSugar;

namespace J.ProductSet.Application.CommandHandler.ClassifiedManagementCommandHandler
{
    public class ClassifiedManagementUpdateCommandHandler : IRequestHandler<ClassifiedManagementUpdateCommand, int>
    {
        private readonly ISqlSugarClient _sqlSugarClient;
        public IMapper _mapper;
        public ClassifiedManagementUpdateCommandHandler(ISqlSugarClient sqlSugarClient, IMapper mapper)
        {
            _sqlSugarClient = sqlSugarClient;
            _mapper = mapper;
        }
        public async Task<int> Handle(ClassifiedManagementUpdateCommand request, CancellationToken cancellationToken)
        {
            ClassifiedManagement modes = _mapper.Map<ClassifiedManagement>(request);
            modes.CreationTime = DateTime.Now;
            return await _sqlSugarClient.Updateable(modes).ExecuteCommandAsync();
        }
    }
}
